package com.csc.base;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;

/**
 * @description:
 * @author: ChenShuCheng
 * @create: 2021-03-11 15:32
 **/
public class IoSession {

    private Channel channel;

    public IoSession(Channel channel) {
        this.channel = channel;
    }


    public void sendMessage(String msg){
        if (msg == null) {
            return;
        }
        if (channel != null) {
            byte[] bytes = msg.getBytes();
            ByteBuf buffer = Unpooled.buffer(bytes.length);
            buffer.writeBytes(bytes);
            channel.writeAndFlush(buffer);
        }
    }
}
